package com.liuchuanzheng.lcz_wanandroid.room

import androidx.room.*
import com.liuchuanzheng.lcz_wanandroid.module.home.bean.Article
import com.liuchuanzheng.lcz_wanandroid.module.home.bean.Tag

/**
 * @author 刘传政
 * @date 2021/9/22 0022 14:23
 * QQ:1052374416
 * 电话:18501231486
 * 作用:
 * 注意事项:
 */
@Dao
interface ReadHistoryDao {
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertArticle(article: Article):Long

    @Insert(entity = Tag::class, onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertTag(tag: Tag): Long

    @Transaction
    @Query("SELECT * FROM article ORDER BY readTime DESC")
    suspend fun queryAllReadHistory(): List<ReadHistory>

    @Transaction
    @Query("SELECT * FROM article WHERE id = :id")
    suspend fun queryReadHistory(id: Long): ReadHistory?

    @Delete(entity = Article::class)
    suspend fun deleteArticle(article: Article)

    @Delete(entity = Tag::class)
    suspend fun deleteTag(tag: Tag)
}